<template>
	<view class="productlist">
		<view class="top">
			<image src='../../static/businessImg/back.png' class="topback" @click="back">
			</image>
			<view class="topname">
				选择产品
			</view>

			<view class="searchview">
				<u-search placeholder="搜索" v-model="keyword" :show-action="false" @change="handleSearch"></u-search>
			</view>
		</view>

		<view class="productcneter">
			<view class="productcneteritem" v-for="item in list" :key="item.id">
				<image :src="item.image" class="productcneteritemimg"></image>

				<view class="productcneteritemname">
					{{item.name}}
				</view>

				<view class="productcneteritemprice">
					￥ {{item.price}}
				</view>

				<view class="productcneteritembtn" @click="handleGotiezishanchuan(item)">
					选择
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		storeProList,
	} from '@/api/storeAdmin.js'
	
	import { supplierStoreProList } from "@/api/gongyingshang.js";
	
	import storage from '@/utils/storage.js';
	export default {
		data() {
			return {
				keyword: '',
				page: 1,
				pageSize: 10,
				list: [ ],
				from: "",
			}
		},

		onReachBottom() {
			this.page = this.page + 1;
			this.getList()
		},
		
		onLoad(option) {
			this.from = option.from
		},
		
		onShow() {
			this.list = [];
			this.page = 1;
			this.getList()
		},
		methods: {
			back() {
				uni.navigateBack({
					delta: 1
				});
			},

			handleSearch() {
				this.page = 1;
				this.list = [];
				this.getList()
			},
			
			
			getList(){
				const { from, keyword, page, pageSize}  = this;
				let that = this;
				if(from == 'gys'){
					supplierStoreProList({
						typeId: 0,
						page,
						limit:pageSize,
						id: storage.getUserInfo().storeId,
						keyword
					}).then(res => {
						that.list = [...that.list, ...res.data.list];
						
					})
				}else{
					storeProList({
						storeId: storage.getUserInfo().storeId,
						type: 0,
						page: page,
						limit: pageSize,
						keyword
					}).then(res => {
						that.list = [...that.list, ...res.data.list];
						
					})
				}
			},

			handleGotiezishanchuan(product){
				const pages = getCurrentPages();
				const prevPage = pages[pages.length - 2]; 
				prevPage.$vm.setData({
				  someData: {...product}
				});
				uni.navigateBack();
			}
		}
	}
</script>

<style scoped>
	.productlist {
		width: 100%;
		min-height: 100vh;
	}

	.top {
		width: 100%;
		height: 250rpx;
		position: relative;
		background: #FFFFFF;
	}

	.topback {
		width: 16rpx;
		height: 29rpx;
		position: absolute;
		top: 106rpx;
		left: 32rpx;
	}

	.topname {
		width: 300rpx;
		height: 32rpx;
		text-align: center;
		font-family: Adobe Heiti Std;
		font-weight: normal;
		font-size: 33rpx;
		color: #222222;
		line-height: 32rpx;
		position: absolute;
		top: 104rpx;
		left: 50%;
		transform: translateX(-50%);
	}

	.searchview {
		position: absolute;
		width: 612rpx;
		height: 58rpx;
		top: 159rpx;
		left: 50%;
		transform: translateX(-50%);
	}

	.productcneter {
		padding: 0 34rpx;
		margin-top: 31rpx;
		width: 100%;
	}

	.productcneteritem {
		width: 100%;
		height: 160rpx;
		position: relative;
		margin-bottom: 30rpx;
	}

	.productcneteritemimg {
		width: 160rpx;
		height: 160rpx;
		position: absolute;
		top: 0;
		left: 0;
	}

	.productcneteritemname {
		width: 462rpx;
		font-family: PingFang;
		font-weight: bold;
		font-size: 26rpx;
		color: #151F38;
		position: absolute;
		top: 10rpx;
		left: 180rpx;
	}

	.productcneteritemprice {
		width: 300rpx;
		position: absolute;
		bottom: 5rpx;
		left: 180rpx;
		font-family: PingFang;
		font-weight: 500;
		font-size: 24rpx;
		color: #FF3A3A;
	}

	.productcneteritembtn {
		width: 105rpx;
		height: 45rpx;
		text-align: center;
		line-height: 45rpx;
		background: rgb(148, 207, 57);
		border-radius: 25rpx;
		font-family: Adobe Heiti Std;
		font-weight: normal;
		font-size: 32rpx;
		color: #FFFFFF;
		position: absolute;
		bottom: 5rpx;
		right: 40rpx;
	}
</style>
